<?php

namespace App\Services\Admin;


use App\Models\Metro;
use App\Models\MetroStation;

class MetroService
{
    public function getMetroById($id)
    {
        return Metro::findOrFail($id);
    }

    public function getMetroByCity($id)
    {
        $metro = Metro::where('region_id',$id)->where('status','T')->orderBy('sort','asc')->get();
        if (count($metro)){
            return response()->json([
                'code' => 0,
                'metro' => $metro
            ]);
        }else{
            return response()->json([
                'code' => 1
            ]);
        }
    }

    public function getMetroByCityId($id)
    {
        return Metro::where('region_id',$id)->where('status','T')->orderBy('sort','asc')->get();
    }

    public function getStationByMetroId($id)
    {
        $station = MetroStation::where('metro_id',$id)->where('status','T')->orderBy('sort','asc')->get();
        if (count($station)){
            return response()->json([
                'code' => 0,
                'station' => $station
            ]);
        }else{
            return response()->json([
                'code' => 1
            ]);
        }
    }

}